package com.dominos.voldemortstress;

import java.lang.management.ManagementFactory;

import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;

public class StartAsService {

	/**
	 * @param args
	 * @throws InterruptedException
	 * @throws NullPointerException
	 * @throws MalformedObjectNameException
	 * @throws NotCompliantMBeanException
	 * @throws MBeanRegistrationException
	 * @throws InstanceAlreadyExistsException
	 */
	public static void main(String[] args) throws InterruptedException,
			MalformedObjectNameException, NullPointerException,
			InstanceAlreadyExistsException, MBeanRegistrationException,
			NotCompliantMBeanException {
		MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
		ObjectName voldemortStressObjectName = new ObjectName(
				"com.dominos.voldemortstress:type=VoldemortStress");
		ObjectName stressParametersObjectName = new ObjectName(
				"com.dominos.voldemortstress:type=StressParameters");
		ObjectName stressClientConfigObjectName = new ObjectName(
		"com.dominos.voldemortstress:type=StressClientConfig");

		String bootstrapUrl = "tcp://localhost:6666";
		StressClientConfig clientConfig = new StressClientConfig();
		clientConfig.setBootstrapUrls(bootstrapUrl);

		StressParameters stressParameters = new StressParameters();
		stressParameters.setNumberofWriteThreads(10);
		stressParameters.setSizeOfWriteData(25000);
		stressParameters.setNumberofReadThreads(10);
		stressParameters.setStoreName("stressTestStore");
		stressParameters.setLogFilePath("LogFileForBDBParameters.csv");

		VoldemortStress voldemortStress = new VoldemortStress();
		voldemortStress.setClientConfig(clientConfig);
		voldemortStress.setStressParameters(stressParameters);

		voldemortStress.connectToStore();

		mbs.registerMBean(voldemortStress, voldemortStressObjectName);
		mbs.registerMBean(stressParameters, stressParametersObjectName);
		mbs.registerMBean(clientConfig, stressClientConfigObjectName);

		System.out.println("Connected to the store: "
				+ stressParameters.getStoreName());
		Thread.sleep(Long.MAX_VALUE);

	}

}
